# Contributor: Thomas Liske <thomas@fiasko-nw.net>
# Maintainer: Thomas Liske <thomas@fiasko-nw.net>
pkgname=accel-ppp
_pkgver=1.12.0-181-g85beb6b
pkgver=${_pkgver%-*}
pkgver=${pkgver/-/.}
pkgrel=0
pkgdesc="PPtP/L2TP/PPPoE/SSTP server for Linux"
url="https://accel-ppp.org/"
arch="all"
license="GPL-2.0-or-later"
makedepends="cmake lua5.4-dev openssl1.1-compat-dev pcre-dev net-snmp-dev linux-headers
	libucontext-dev"
subpackages="$pkgname-doc $pkgname-openrc"
source="accel-ppp-$_pkgver.tar.gz::https://github.com/accel-ppp/accel-ppp/archive/refs/tags/$_pkgver.tar.gz
	0001-ucontext.patch
	0002-printf.patch
	0003-tsearch.patch
	0004-if_arp.patch
	accel-pppd.initd
	"
builddir="$srcdir/accel-ppp-$_pkgver"

build() {
	export LDFLAGS="$LDFLAGS -Wl,-z,lazy"
	if [ "$CBUILD" != "$CHOST" ]; then
		CMAKE_CROSSOPTS="-DCMAKE_SYSTEM_NAME=Linux -DCMAKE_HOST_SYSTEM_NAME=Linux"
	fi
	cmake -B build \
		-DLIB_SUFFIX= \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DCMAKE_INSTALL_SYSCONFDIR=/etc \
		-DCMAKE_INSTALL_LOCALSTATEDIR=/var \
		-DSHAPER=TRUE \
		-DRADIUS=TRUE \
		-DLUA=TRUE \
		-DLUA=5.4 \
		-DNETSNMP=TRUE \
		$CMAKE_CROSSOPTS .
	make -C build
}

check() {
	build/accel-cmd/accel-cmd -V
	build/accel-pppd/accel-pppd -V
}

package() {
	make -C build install DESTDIR="$pkgdir"
	mv "$pkgdir"/etc/accel-ppp.conf.dist "$pkgdir"/etc/accel-ppp.conf
	install -Dm755 "$srcdir"/accel-pppd.initd "$pkgdir"/etc/init.d/accel-pppd
}

sha512sums="
1554c5b3905ee53fa40f4111c29fcf25865c5a0d185407893fc035b1290a13f479685a29574388d10b7d010ba0b4ed597ce09e914b5128bc3a7a99a620d6649e  accel-ppp-1.12.0-181-g85beb6b.tar.gz
fc49b789e80a6e25863d56711079e5ffe853afb6b6c6caaec9f119813edae4342198b962c659b7a5a3af14afab69daa447efdde8ac6c9a13b6420c697bf9c40f  0001-ucontext.patch
cf793663b2beb85f07f9817286d4e53e9913c33fa1dfe30f1cec8a6b14b143f1f73f995f56f137a96c5645075db76c9268488a7205f17a1a2ebe4e31834a40c1  0002-printf.patch
87210bb02fea7f4af15ab10ae479805ae0b8eb61dcf71b5c7a7f55b725a8df40b20c0907d35f8eaf698d573d0b5d045468fd473bb793fa7b659f8880bd5bbf4a  0003-tsearch.patch
d1e9924a3e7c9f9a189608ec4c009dbcdfefa0dcb1edccf6fe30e66820d490d1132ca59e6d779152c647156008a9b390c0eff87bcef9ac5e3131c075c2139c65  0004-if_arp.patch
f8ed5966e90d4dac126fb51db12bf1ea38dee76bc0a0e23a5968a0ea5a125189bd4be1529a0997c3a2de8fdc7cdab0326613b3a1446b1ada64c900210c390843  accel-pppd.initd
"
